<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
	<style>
        .text-light {
            color: #999 !important;
        }
        .aui-radio {
            width: 1rem;
            height: 1rem;
        }
	</style>
</head>
<body>
    <section class="aui-content">
        <ul class="aui-list aui-form-list" style="margin-top:50px;">
          <li class="aui-list-item">
              <div class="aui-list-item-inner">
                  <div class="aui-list-item-label-icon">
                      <i class="aui-iconfont aui-icon-my"></i>
                  </div>
                  <div class="aui-list-item-input">
                      <input type="text" readonly="readonly" id="users_id" placeholder="请选择成员" onclick="openWin('daily_mail')">
                  </div>
              </div>
          </li>
          <li class="aui-list-item">
              <div class="aui-list-item-inner">
                  <div class="aui-list-item-label-icon">
                      <i class="aui-iconfont aui-icon-comment"></i>
                  </div>
                  <div class="aui-list-item-input">
                      <input type="text" id="group_name" placeholder="请输入群组名称">
                  </div>
              </div>
          </li>
        </ul>
        <div class="aui-content aui-margin-15">
        	<div class="aui-btn aui-btn-info aui-btn-block aui-btn-sm" onclick="saveInfo()">提交</div>
        </div>
    </section>
</body>
<script type="text/javascript" src="../script/zepto.min.js" ></script>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript">
    apiready = function(){
        api.parseTapmode();
    };

    function openWin(name) {
        api.openWin({
            name: name,
            url: name+'_win.html',
            pageParam: {
                winName: "add_group",
                frameName:"add_group_frm"
            }
        });
    }

    function selectUsers(val){
      $("#users_id").val(val);
    }

    //提交创建群组信息
    function saveInfo(){
        var usersId = $("#users_id").val();
        var groupName = $("#group_name").val();
        if(groupName && usersId){
            api.ajax({
                url: ServeUrl + "m=Index&a=getUsers",
                method: 'post',
                data: {
                    values: {
                        usersId: usersId
                    }
                }
            }, function(ret, err) {
                //alert(JSON.stringify(ret));
                if(ret.status == 1){

                    var   usersIdArr = new Array;
                    for (var i = 0; i < ret.data.length; i++) {
                        usersIdArr[i] = ret.data[i].ryId;
                    }
                    var usersIdstr=usersIdArr.join('","');
                    usersIdstr = '["'+usersIdstr+'"]';

                    api.sendEvent({
                        name:'createGroupChat',
                        extra:{
                            groupName:groupName,
                            usersId:usersIdstr,
                            usersStr:usersId
                        }
                    })
                }
            })

        }else {
            api.toast({
                msg:'请完善群组信息'
            });
        }
    }
</script>
</html>
